﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display {
    import flash.events.*;
    import flash.display.*;
    import flash.geom.*;
    import Engine.Helpers.*;
    import flash.utils.*;
    import Display.DialogUI.*;
    import org.aswing.*;
    import Classes.util.*;
    import Display.aswingui.*;

    public class NotifyPopup extends GenericDialog {

        public static const DISAPPEAR_TIMEOUT:int = 6000;

        protected var m_disappearTimer:Timer = null;
        protected var m_appearPos:Vector2 = null;
        protected var m_timeout:int = 0;

        public function NotifyPopup(_arg1:Function=null, _arg2:String=null, _arg3:int=6000){
            super(_arg2, "", 0, _arg1, "", "", false);
            m_centered = false;
            this.m_timeout = _arg3;
        }
        override protected function init():void{
            m_holder = new Sprite();
            this.addChild(m_holder);
            m_jwindow = new JWindow(m_holder);
            m_content = m_holder;
            m_content.addEventListener("close", closeMe, false, 0, true);
        }
        override protected function loadAssets():void{
            Global.delayedAssets.get(DelayedAssetLoader.POPULATION_ASSETS, makeAssets);
        }
        override protected function onAssetsLoaded(_arg1:Event=null):void{
            m_jpanel = this.createDialogView(this.createAssetDict());
            finalizeAndShow();
            this.m_appearPos = new Vector2(38, (472 - 25));
            this.x = this.m_appearPos.x;
            this.y = this.m_appearPos.y;
            ASwingHelper.prepare(m_jpanel);
            ASwingHelper.prepare(m_jwindow);
            this.buttonMode = true;
            this.mouseChildren = false;
        }
        override protected function doTrackDialogActions():Boolean{
            return (false);
        }
        override protected function createDialogView(_arg1:Dictionary):GenericDialogView{
            return (new NotifyPopupView(_arg1, m_message, m_title, m_type, m_callback));
        }
        override protected function createAssetDict():Dictionary{
            var _local1:Dictionary = new Dictionary();
            _local1["bgAsset"] = (new m_comObject.neighborBar_populationPopup() as DisplayObject);
            return (_local1);
        }
        public function showTimed():void{
            if (m_jpanel){
                (m_jpanel as NotifyPopupView).rebuild(NotifyPopupView.STATE_SHORT);
                ASwingHelper.prepare(m_jwindow);
                super.show();
                this.restartDisappearTimer();
            };
        }
        public function showOnTimed():void{
            if (m_jpanel){
                ASwingHelper.prepare(m_jwindow);
                super.show();
                this.stopDisappearTimer();
            };
        }
        override public function show():void{
            if (m_jpanel){
                (m_jpanel as NotifyPopupView).rebuild(NotifyPopupView.STATE_LONG);
                ASwingHelper.prepare(m_jwindow);
                super.show();
                this.stopDisappearTimer();
            };
        }
        override public function hide():void{
            super.hide();
            this.stopDisappearTimer();
        }
        protected function restartDisappearTimer():void{
            if (this.m_disappearTimer == null){
                this.m_disappearTimer = new Timer(this.m_timeout);
                this.m_disappearTimer.start();
                this.m_disappearTimer.addEventListener(TimerEvent.TIMER, this.onTimer, false, 0, true);
            } else {
                this.m_disappearTimer.reset();
                this.m_disappearTimer.start();
            };
        }
        protected function stopDisappearTimer():void{
            if (this.m_disappearTimer){
                this.m_disappearTimer.stop();
            };
        }
        protected function onTimer(_arg1:TimerEvent):void{
            if (this.m_disappearTimer){
                this.m_disappearTimer.stop();
            };
            this.hide();
        }
        override protected function hideTween(_arg1:Function):void{
            this.mouseEnabled = (this.mouseChildren = false);
            _arg1();
        }
        override protected function showTween():void{
            this.mouseEnabled = (this.mouseChildren = false);
            var _local1:Point = new Point(m_content.width, m_content.height);
            var _local2:Matrix = new Matrix();
            _local2.translate((-(_local1.x) / 2), (-(_local1.y) / 2));
            _local2.scale(1, 1);
            _local2.translate((_local1.x / 2), (_local1.y / 2));
            m_content.transform.matrix = _local2;
            if (m_centered){
                centerPopup();
            };
            this.onShowComplete();
        }
        override public function onShowComplete():void{
            this.x = this.m_appearPos.x;
            this.y = this.m_appearPos.y;
        }
        public function setAppearPos(_arg1:Vector2):void{
            this.m_appearPos = _arg1;
        }

    }
}//package Display 
